package com.ruoyi.web.controller.storage;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.storage.packageWeighing.domain.Package;
import com.ruoyi.storage.packageWeighing.service.IPackageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 包装称重Controller
 * 
 * @author zzx
 * @date 2024-02-04
 */
@RestController
@RequestMapping("/packageWeighing/package")
public class PackageController extends BaseController
{
    @Autowired
    private IPackageService packageService;

    /**
     * 查询包装称重列表
     */
    @PreAuthorize("@ss.hasPermi('packageWeighing:package:list')")
    @GetMapping("/list")
    public TableDataInfo list(Package packagew)
    {
        startPage();
        List<Package> list = packageService.selectPackageList(packagew);
        return getDataTable(list);
    }
    /**
     * 查询包装称重列表
     */
    @GetMapping("/bicycle/list")
    public TableDataInfo listBicycle(Package packagew)
    {
        startPage();
        List<Package> list = packageService.selectPBicycleList(packagew);
        return getDataTable(list);
    }
    /**
     * 导出包装称重列表
     */
    @PreAuthorize("@ss.hasPermi('packageWeighing:package:export')")
    @Log(title = "包装称重", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Package packagew)
    {
        List<Package> list = packageService.selectPackageList(packagew);
        ExcelUtil<Package> util = new ExcelUtil<Package>(Package.class);
        util.exportExcel(response, list, "包装称重数据");
    }

    /**
     * 获取包装称重详细信息
     */
    @PreAuthorize("@ss.hasPermi('packageWeighing:package:query')")
    @GetMapping(value = "/{bicycleId}")
    public AjaxResult getInfo(@PathVariable("bicycleId") String bicycleId)
    {
        return success(packageService.selectPackageByBicycleId(bicycleId));
    }

    /**
     * 新增包装称重
     */
    @PreAuthorize("@ss.hasPermi('packageWeighing:package:add')")
    @Log(title = "包装称重", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Package packagew)
    {
        return toAjax(packageService.insertPackage(packagew));
    }

    /**
     * 修改包装称重
     */
    @PreAuthorize("@ss.hasPermi('packageWeighing:package:edit')")
    @Log(title = "包装称重", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Package packagew)
    {
        return toAjax(packageService.updatePackage(packagew));
    }

    /**
     * 删除包装称重
     */
    @PreAuthorize("@ss.hasPermi('packageWeighing:package:remove')")
    @Log(title = "包装称重", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bicycleIds}")
    public AjaxResult remove(@PathVariable String[] bicycleIds)
    {
        return toAjax(packageService.deletePackageByBicycleIds(bicycleIds));
    }
    /**
     * 判断是否采集
     */
    @GetMapping(value = "/selectStatus/{bicycleId}")
    public AjaxResult getStatus(@PathVariable("bicycleId") String bicycleId)
    {
        System.out.println(bicycleId);
        return packageService.selectPackageStatusByBicycleId(bicycleId);
    }
    /**
     * 审核状态
     */
    @PreAuthorize("@ss.hasPermi('system:bicycle:edit')")
    @Log(title = "ControlAcquisition", businessType = BusinessType.UPDATE)
    @PutMapping("/audit/{bicycleIds}")
    public AjaxResult editOrderAudit(@PathVariable String[] bicycleIds)
    {
        return packageService.updateBicycleAudit(bicycleIds);
    }
    /**
     * 反审核状态
     */
    @PreAuthorize("@ss.hasPermi('system:bicycle:edit')")
    @Log(title = "ControlAcquisition", businessType = BusinessType.UPDATE)
    @PutMapping("/unaudit/{bicycleIds}")
    public AjaxResult editOrderUnAudit(@PathVariable String[] bicycleIds)
    {
        return packageService.updateBicycleUnAudit(bicycleIds);
    }

}
